<?php

namespace App\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

class ConvertParamCommand extends Command
{
    protected static $defaultName = 'convert:param';
    protected static $defaultDescription = '转换get参数为key:value';

    protected function configure(): void
    {
        $this
            ->addArgument('params', InputArgument::OPTIONAL, '参数字符串');
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $io = new SymfonyStyle($input, $output);
        $params = $input->getArgument('params');

        $paramArr = explode('&', $params);
        $str = '';
        foreach ($paramArr as $p) {
            $kv = explode('=', $p);
            $str .= "{$kv[0]}: {$kv[1]}\n";
        }
        var_dump($str);
        return Command::SUCCESS;
    }
}
